<?php
/**
 * Created by PhpStorm.
 * User: DongYao
 * Date: 2018/1/31
 * Time: 下午6:56
 */

namespace XmtApp\Modules\Admin\Controllers\Api;


use App\Http\Resources\MobileSmsesResource;
use App\Tables\MobileSms;
use Illuminate\Http\Request;

class MessageController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 查询操作日志
     * @param Request $request
     * @return OperationLogsResource
     */
    public function smsList(Request $request)
    {
        $query = new MobileSms();

        if ($request->filled('status')) {
            $query = $query->where('status', $request->status);
        }

        if ($request->filled('keyword')) {
            $query = $query->where(function ($query) use ($request) {
                $query->orWhere('mobile', 'like', "%{$request->keyword}%");
                $query->orWhere('content', 'like', "%{$request->keyword}%");
            });
        }

        if ($request->filled('created_at')) {
            $query = $query->whereBetween('created_at', $request->created_at);
        }

        $query = $query->orderBy('id', 'desc');
        $data = $query->paginate($request->header('pageSize'));

        return new MobileSmsesResource($data);
    }
}